/**
 * index.js
 * import('./title.js').then(result=>{
 *    console.log('result',result)
 * })
 */

/**
  * title.js
  * module.exports = {
      age: 'age',
      name: 'name'
    }
*/

/**
 * require.r  -->  标识这是一个esModule模块
 * require.d  -->  将导出的内容进行赋值,导入esModule需要
 * require.n  -->  需要兼容获取default的内容
 * require.m  -->  modules
 * require.f  -->  {}
 * reuqire.f.j --> 第一次异步加载和缓存逻辑
 * require.l  -->  加载script标签
 * require.e  -->  异步加载入口
 * webpack在ast解析时解析到`import`语法时，就会知道该模块是esModule模块，会使用`require.r`进行标记
 */

var modules = {}

var cache = {}

function require(moduleId){
  if(cache[moduleId] != undefined){
    return cache[moduleId].exports
  }
  var module = cache[moduleId] = {exports: {}}
  modules[moduleId](module,module.exports,require)
  return module.exports
}

require.r = function(exports){
  Object.defineProperty(exports, Symbol.toStringTag, {value: 'Module'}); // [object Module]
  Object.defineProperty(exports, '__esModule', {value: true})
}

require.d = function(exports, defines){
  for (const key in defines) {
   Object.defineProperty(exports, key, {
     get: defines[key],
     enumerable: true
   })
  }
}

require.n = function(module){
  var getter = module.__esModule? () => module.default: () => module
  return getter
}

require.e = function(chunkId){
  var promises = []
  Object.keys(require.f).forEach(key=>{
    let func = require.f[key]
    func(chunkId,promises)
  })
  return Promise.all(promises)
}
require.p = ''  // webpack配置中的publicPath
require.u = (chunkId) => chunkId + '.js'  //chunkId一般是文件名，加上后缀为文件路径
require.f = {}
require.f.j = function(chunkId,promises){
  var installedChunkData = require.o(installedChunks,chunkId)? installedChunks[chunkId]: undefined
    if(installedChunkData !== 0){  // !==0,说明该异步加载还未结束
      if(installedChunkData){   //installedChunkData有值说明不是第一次异步加载
        promises.push(installedChunkData[2])  // chunk[2] 是promise，同一个chunkId的promise为同一个
      }else{
        var promise = new Promise((resolve,reject)=>{
          installedChunks[chunkId] = installedChunkData = [resolve,reject]   // 收集promise的状态，当异步加载成功后调用resove通知成功,执行Promise.all内部逻辑
        })
        installedChunkData.push(promise)
        promises.push(promise)
        var url = require.p + require.u(chunkId)
        require.l(url)
      }
    }
}

require.l = function(url){
    var script = document.createElement('script')
    script.src = url
    document.head.appendChild(script)
}

var chunkLoadingGobal = window['异步加载'] || (window['异步加载'] = {})
chunkLoadingGobal.push = webpackJsonpCallback
function webpackJsonpCallback(data){
  var [chunkIds, moreModules] = data
  for (const chunkId in moreModules) {
    require.m[chunkId] = moreModules[chunkId]
  }

  for (let i = 0; i < chunkIds.length; i++) {
    const chunkId = chunkIds[i];
    installedChunks[chunkId][0]()  // 让promise的状态为成功态
    installedChunks[chunkId] = 0   // 让异步加载为成功 0 == 成功
  }
}
require.o = (object,key) => Object.prototype.hasOwnProperty.call(object,key)

// var exports = {}
// require.r(exports)
require.m = modules
var installedChunks = {
  main: 0
}
document.body.addEventListener('click', function(){
  console.log('1111');
  require.e('src_title_js').then(require.bind(require,'src_title_js')).then(result=>{
    console.log('age',result.age);
    console.log('result',result);
  })
})
